package com.acwing.partition19;

import java.io.*;
import java.util.ArrayDeque;
import java.util.Queue;

/**
 *          *  *  *  *     *                 *
 * 0  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15
 * @author `RKC`
 * @date 2022/1/25 18:55
 */
public class AC1855愤怒的奶牛_bfs {

    private static final int N = 110;
    private static int[] nums = new int[N];
    private static int n = 0;
    private static Queue<Integer> queue = new ArrayDeque<>(N);
    private static boolean[] st = new boolean[N];

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        n = Integer.parseInt(reader.readLine());
        for (int i = 0; i < n; i++) nums[i] = Integer.parseInt(reader.readLine());
        //枚举每一个起爆点
        int ans = 0;
        for (int i = 0; i < n; i++) ans = Math.max(ans, bfs(i));
        writer.write(ans + "\n");
        writer.flush();
    }

    private static int bfs(int s) {
        queue.clear();
        int ans = 0, r = 1;
        for (int i = 0; i <= n; i++) st[i] = false;
        queue.add(s);
        st[s] = true;
        while (!queue.isEmpty()) {
            int size = queue.size();
            for (int k = 0; k < size; k++) {
                int u = queue.poll();
                ans++;
                //查找[u-r,u+r]范围内的草并加入到队列
                for (int i = 0; i < n; i++) {
                    if (nums[i] >= nums[u] - r && nums[i] <= nums[u] + r) {
                        if (st[i] || u == i) continue;
                        queue.add(i);
                        st[i] = true;
                    }
                }
            }
            r++;
        }
        return ans;
    }
}
